<template>
  <card-layout title="方案编制情况" class="chart">
    <template #extra>
      <el-icon class="extra-more" :size="22">
        <Menu />
      </el-icon>
    </template>
    <div class="card-container">
      <div class="stat-group">
        <div class="item">
          <div class="value">40</div>
          <div class="label">采矿权个数</div>
        </div>
        <div class="item">
          <div class="value">40</div>
          <div class="label">方案编制</div>
        </div>
        <div class="item">
          <div class="value">4</div>
          <div class="label">新增/修编</div>
        </div>
      </div>
      <div class="chart-container">
        <div style="width: 100%; height: 100%" ref="chartRef"></div>
      </div>

    </div>
  </card-layout>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import useChart from "@/hooks/useCharts.js";
const chartRef = ref(null);
let { chartInstance } = useChart(chartRef);

// 初始化图表
const initChart = () => {
  const option = {
    tooltip: {
      show: false,
    },
    legend: { show: false },
    grid: {
      show: false,
      top: 0,
      bottom: 0,
      right: 12,
      left: 12,
      containLabel: true,
    },
    xAxis: {
      type: 'value',
      boundaryGap: [0, 0.01],
      axisLine: {
        show: false,
      },
      splitLine: {
        show: false,
      }
    },
    yAxis: {
      type: 'category',
      data: ['采矿权', '方案编制', '新增/修编'],
      splitLine: {
        show: false,
      }
    },
    series: [
      {
        showBackground: true,
        name: '方案编制',
        type: 'bar',
        data: [40, 40, 4]
      },

    ]
  };
  chartInstance.value.setOption(option);
};

onMounted(() => {
  initChart();
});
</script>

<style lang="scss" scoped>
.chart {
  box-sizing: border-box;
  flex: 0.6;

  .card-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    padding: 8px;
  }

  .chart-container {
    flex: 1;
    width: 100%;
    position: relative;

    .chart-label {
      user-select: none;
      position: absolute;
      pointer-events: none;
      top: 0px;
      left: 0px;
      z-index: 1;
      height: 100%;
      width: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;

      .percent {
        font-size: 26px;
        color: #fff;
      }

      .txt {
        color: #dedede;
        font-size: 14px;
      }
    }
  }

  .stat-group {
    margin-bottom: 8px;
  }

}
</style>
